package com.jnzc.ocr.rest.app.shop.controller.app;

import com.jnzc.ocr.common.bean.Tree;
import com.jnzc.ocr.common.vo.UserVo;
import com.jnzc.ocr.dependencies.rest.base.BaseController;
import com.jnzc.ocr.serv.shop.api.ShopProductAttrApi;
import com.jnzc.ocr.serv.shop.entity.ShopProductAttr;
import com.jnzc.ocr.serv.shop.vo.ShopProductAttrSaveVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhangcm
 * @version 1.0, 2017-11-26
 */
@Api(tags = {"app - 产品属性接口"})
@RestController
@RequestMapping("/app/shopProductAttr")
public class AppProductAttrController extends BaseController {

    @Autowired
    private ShopProductAttrApi shopProductAttrApi;

    @ApiOperation(value = "详情")
    @GetMapping("")
    public List<Tree<ShopProductAttr>> info(){
        UserVo userVo = super.get();
        return shopProductAttrApi.listTree(userVo.getShopId());
    }

    @ApiOperation(value = "保存")
    @PostMapping("")
    public void save(@RequestBody ShopProductAttrSaveVo param){
        UserVo userVo = super.get();
        shopProductAttrApi.save(param, userVo.getShopId());
    }

    @ApiOperation(value = "删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "产品属性ID", required = true, paramType = "path")
    })
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id){
        UserVo userVo = super.get();
        shopProductAttrApi.delete(id, userVo.getShopId());
    }

}
